package com.grapecc.springcloud.controller;

import com.grapecc.springcloud.entities.CommonResult;
import com.grapecc.springcloud.entities.Payment;
import com.grapecc.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 卖糖的兜兜
 * @version 1.0.0
 * @ClassName PaymentController.java
 * @Description TODO
 * @createTime 2022年02月02日 21:01:00
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String port;

    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int i = paymentService.create(payment);
        if (i > 0){
            return new CommonResult(200,"添加成功! serverprot:"+port ,payment);
        }else {
            return new CommonResult(444,"添加失败! serverprot:"+port ,payment);
        }
    }
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult getPaymentId(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentId(id);
        if (payment != null){
            return new CommonResult(200,"查询成功!port"+port,payment);
        }else {
            return new CommonResult(444,"查询失败!port"+port,payment);
        }
    }


    @GetMapping(value = "/payment/lb")
    public String getPaymentLB()
    {
        return port;
    }
}
